home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoDeleteSmallObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.5 KB  |  217 lines

  1. /*
  2.  *   $RCSfile: undoDeleteSmallObj.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "openlog.h"
  61. #include "logrecs.h"
  62. #include "logaction.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "sm_extfuncs.h"
  70. #include "thread_globals.h"
  71. #include "bf_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #   include "log_globals.h"
  75. #endif
  76.  
  77.  
  78.  void
  79. undoDeleteSmallObj (
  80.  
  81.     LOGRECORDHDR        *recordHeader 
  82. )
  83. {
  84.  
  85.     GROUPLINK            *groupLink;
  86.     SLOTTEDPAGE            *slottedPage;
  87.     PID                    *pid;
  88.     WRITEINFO              *opInfo;        /* info on logged operation */
  89.     FULLWRITEINFO         *fullOpInfo;    /* info on no data operation */
  90.     char                *data;
  91.     int                    dataSize;
  92.     OID                    oid;
  93.     LOGRECORDINFO       recordInfo;
  94. #ifdef INIT_LRC_IS_LSN
  95.     LRC                 tempLRC;
  96.     LRC                 *lrc = &tempLRC;
  97. #else
  98.     LRC                 *lrc;
  99. #endif /* INIT_LRC_IS_LSN; */
  100.     LSN                 lsn;
  101.     FORCEMARK           forceMark;
  102.     BOOL                actionDone; /* Indicates whether the action
  103.                                        was ever performed on the page */
  104.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  105.  
  106.  
  107.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  108.  
  109.     /* get a pointer to the page for the record */
  110.     pid = &(recordHeader->actionPid);
  111.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  112.  
  113.     if (recordHeader->action == LOG_ACTION_DELETE_SMALL_OBJ) {
  114.         /* get pointer to destroy info */
  115.         opInfo = (WRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  116.  
  117.         /* get pointer to header, data */
  118.         data = GET_LOG_IMAGE(recordHeader, 1);
  119.         dataSize = GET_LOG_IMAGE_SIZE(recordHeader, 1);
  120.     } else {
  121.         SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_DELETE_SMALL_OBJ_ND);
  122.         fullOpInfo = (FULLWRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  123.         opInfo = &(fullOpInfo->common);
  124.         dataSize = fullOpInfo->size;
  125.         data = NULL;
  126.     }
  127.  
  128.     /* read in the page */
  129.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
  130.         SM_ERROR(TYPE_FATAL, Active->errno);
  131.     }
  132.     groupLink->pageHash->pageType = PAGE_SLOTTED;
  133.  
  134.     /* get a pointer to the slotted page */
  135.     slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  136.     if (CHECK_SLOTTED_MAGIC(slottedPage)) {
  137.         SM_ERROR(TYPE_FATAL, Active->errno);
  138.     }
  139.  
  140.     /* See if the action was actually done */
  141.      actionDone = compareLRC(&(recordHeader->actionLRC), &(slottedPage->header.lrc) ) <= 0;
  142.  
  143.     /*
  144.      *  it is possible that the action
  145.      *  never made it to the page on the server, so missing update
  146.      *  information may need to be recordedjj
  147.      *
  148.      *  Process any missing updates, and return a pointer to
  149.      *  the lrc to increment.  This will either be the lrc on the
  150.      *  slotted page, or the lrc in the missingUpdatePageTable
  151.      */
  152.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  153.                          &(slottedPage->header.lrc),
  154.                          groupLink->pageHash, recordHeader, PAGE_SLOTTED);
  155.  
  156.     /* increment the lrc on the page */
  157.     GENERATE_LRC(lrc);
  158.  
  159.     /*
  160.      *    Log the undo deletion 
  161.      */
  162.     if (recordHeader->action == LOG_ACTION_DELETE_SMALL_OBJ) {
  163.         recordInfo.action       = LOG_ACTION_INSERT_SMALL_OBJ;
  164.         recordInfo.imageCount   = 2;
  165.         recordInfo.imageSize[0] = sizeof(*opInfo);
  166.         recordInfo.imageData[0] = (VOID *) opInfo;
  167.         recordInfo.imageSize[1] = GET_LOG_IMAGE_SIZE(recordHeader, 1);
  168.         recordInfo.imageData[1] = (VOID *)data;
  169.     } else {
  170.         recordInfo.imageCount   = 1;
  171.         recordInfo.imageSize[0] = sizeof(*fullOpInfo);
  172.         recordInfo.imageData[0] = (VOID *) fullOpInfo;
  173.     }
  174.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  175.     recordInfo.actionPid    = pid;
  176.     recordInfo.actionLRC    = lrc;
  177.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  178.     recordInfo.flags        = NOFLAGS;
  179.  
  180.     /* write the record to the log */
  181.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo, &lsn, NOFLAGS)) < 0)  {
  182.         SM_ERROR(TYPE_FATAL, Active->errno);
  183.     }
  184.  
  185.     /* mark the page dependency */
  186. #ifndef INIT_LRC_IS_LSN
  187.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  188. #endif
  189.  
  190.     /*
  191.      *    perform the undo by inserting into the object, assuming
  192.      *    the action was done
  193.      */
  194.     if (actionDone) {
  195.  
  196. #ifdef INIT_LRC_IS_LSN
  197.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  198. #endif
  199.         oid.diskAddr.unique = opInfo->unique;
  200.         oid.diskAddr.slot = opInfo->slot;
  201.         oid.diskAddr.page = pid->page;
  202.         oid.diskAddr.volid = pid->volid;
  203.         if (sm_InsertInSmallObj(slottedPage, data, &oid, opInfo->start, dataSize)) {
  204.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  205.         }
  206.     }
  207.  
  208.     /*
  209.      *    release the semaphore and unfix the page, dirty the page if the
  210.      *  action was done
  211.      */
  212.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  213.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  214.  
  215.     return;
  216. }
  217.